﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WinHBM.Core.Bluetooth;
using WinHBM.Core.DB;

namespace WinHBM.Utils
{
    public class UtilFlower
    {
        private static string TABLE_FLOWER_LOG = "flowerLog";
        private static string TABLE_BABY = "babyInfo";

        public static void localSave(RedFlower flower)
        {

            string redType = "0";

            if (flower.type == FlowerType.Red)
            {
                redType = "0";
            }
            else if (flower.type == FlowerType.Gold)
            {
                redType = "1";
            }

            //数据库保存红花记录
            SQLiteHelper.Instance.insert(
                TABLE_FLOWER_LOG,
                UtilDict.make<string, string>("teacherId", flower.teacherId + "", "babyId", flower.studentId + "", "type", redType, "time", flower.year + "-" + flower.month + "-" + flower.day + " " + flower.hour + ":" + flower.minute + ":" + flower.second)
            );
            //数据库宝宝红花+1
            Dictionary<string, string> dic_condition = UtilDict.make<string, string>("babyId", flower.studentId + "");
            List<Dictionary<string, string>> sqllist = SQLiteHelper.Instance.find(TABLE_BABY, dic_condition);
            if (sqllist.Count > 0)
            {
                Dictionary<string, string> dic = sqllist.First<Dictionary<string, string>>();
                int newRed = Convert.ToInt32(dic["red"]) + 1;
                dic["red"] = newRed.ToString();
                SQLiteHelper.Instance.update(TABLE_BABY, dic, dic_condition);
            }
        }

    }
}
